<template>
  <div class="page-container" >
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>评价管理</span>
        </div>
      </template>
      <el-table
        :data="evaluations"
        style="width: 100%"
        border
        class="evaluation-table"
        stripe
        height="100%"
      >
        <el-table-column prop="orderSn" label="订单编号" width="140" />
        <el-table-column prop="skuName" label="商品名称" min-width="180" />
        <el-table-column prop="score" label="评分" width="80" />
        <el-table-column prop="content" label="评价内容" min-width="200" />
        <el-table-column prop="auditStatus" label="审核状态" width="100">
          <template #default="scope">
            <el-tag :type="getAuditStatusTagType(scope.row.auditStatus)">
              {{ formatAuditStatus(scope.row.auditStatus) }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-model:current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        layout="total, prev, pager, next"
        @current-change="fetchEvaluations"
        class="pagination"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { getEvaluationsService } from '@/api/merchant'
import { useUserInfoStore } from '@/stores/userInfo'

const userInfoStore = useUserInfoStore()
const evaluations = ref([])
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)

const fetchEvaluations = async () => {
  try {
    const res = await getEvaluationsService(currentPage.value, pageSize.value, userInfoStore.userInfo.id )
    console.log(res)
    evaluations.value = res.data.data.records
    total.value = res.data.data.total
  } catch (error) {
    ElMessage.error('获取评价列表失败')
  }
}

const formatAuditStatus = (status) => {
  switch (status) {
    case 0: return '待审'
    case 1: return '通过'
    case 2: return '拒绝'
    default: return '-'
  }
}

const getAuditStatusTagType = (status) => {
  switch (status) {
    case 0: return 'warning'
    case 1: return 'success'
    case 2: return 'danger'
    default: return ''
  }
}

fetchEvaluations()
</script>

<style lang="scss" scoped>
.page-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.box-card {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.card-header {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-color);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
}

.evaluation-table {
  flex: 1;
  overflow: hidden;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  background-color: var(--card-bg);
}
</style>